package com.yunmang.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yunmang.R;
import com.yunmang.activity.exception.ExceptionHandleActivity;
import com.yunmang.app.AppConstant;
import com.yunmang.entity.ExceptionQueryBean;
import com.yunmang.utils.CommonUtils;
import com.yunmang.utils.ViewHolderUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24.
 */
public class ExceptionAllAdapter extends BaseAdapter{
    private List<ExceptionQueryBean.ModelBean.ItemsBean> datalist;
    private Context context;
    public ExceptionAllAdapter(Context context,List<ExceptionQueryBean.ModelBean.ItemsBean> datalist){
        this.context=context;
        this.datalist=datalist;
    }
    @Override
    public int getCount() {
        return datalist.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        final ExceptionQueryBean.ModelBean.ItemsBean itemsBean = datalist.get(i);
        if(convertView==null)
            convertView=View.inflate(context, R.layout.item_exception,null);
        TextView tv_hdbh=ViewHolderUtils.get(convertView,R.id.tv_hdbh);
        TextView tv_apply_depname=ViewHolderUtils.get(convertView,R.id.tv_apply_depname);
        TextView tv_damage_num=ViewHolderUtils.get(convertView,R.id.tv_damage_num);
        TextView tv_date_handle=ViewHolderUtils.get(convertView,R.id.tv_date_handle);
        TextView tv_damage_reason=ViewHolderUtils.get(convertView,R.id.tv_damage_reason);
        TextView tv_status=ViewHolderUtils.get(convertView,R.id.tv_status);
        ImageView iv_status=ViewHolderUtils.get(convertView,R.id.iv_status);
        TextView tv_handle=ViewHolderUtils.get(convertView,R.id.tv_handle);
        tv_hdbh.setText(itemsBean.getHdbh());
        tv_apply_depname.setText(itemsBean.getChargeDepartmentName());
        tv_damage_num.setText(itemsBean.getNumbers()+"");
        tv_date_handle.setText(itemsBean.getApplyAt().substring(0,10));
        tv_damage_reason.setText(itemsBean.getApplyReason());
        int status = itemsBean.getStatus();
        if(AppConstant.orgInfo.getType()==1||AppConstant.orgInfo.getType()==2){
            if(status==1){
                tv_handle.setVisibility(View.GONE);
            }else{
                tv_handle.setVisibility(View.VISIBLE);
            }
        }
        tv_handle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppConstant.exceptionBean=itemsBean;
                context.startActivity(new Intent(context, ExceptionHandleActivity.class));
            }
        });

        switch (status){
            case 0:
                iv_status.setImageResource(R.mipmap.icon_ycgl40_wcl);
                tv_status.setText("未处理");
                tv_status.setTextColor(context.getResources().getColor(R.color.yellow));
                break;
            case 1:
                iv_status.setImageResource(R.mipmap.icon_ycgl40_tg);
                tv_status.setText("已处理通过");
                tv_status.setTextColor(context.getResources().getColor(R.color.green3));
                break;
            case 2:
                iv_status.setImageResource(R.mipmap.icon_ycgl40_wtg);
                tv_status.setText("已处理未通过");
                tv_status.setTextColor(context.getResources().getColor(R.color.red));
                break;
        }
        return convertView;
    }


    public  void refresh(List<ExceptionQueryBean.ModelBean.ItemsBean> datalist){
        this.datalist=datalist;
        notifyDataSetChanged();
    }
}
